package com.spring.component.auth.utils;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;

/**
 * @author liushihua
 * @since 2018年03月23日
 */
public class EncryptUtil {
  private static String SITE_WIDE_SECRET = "35637289C2354E38B5FC743983DFBDD6";
  private static PasswordEncoder ENCODER = new StandardPasswordEncoder(SITE_WIDE_SECRET);

  /**
   * 加密
   * 
   * @param rawPassword
   * @return
   */
  public static String encrypt(String rawPassword) {
    return ENCODER.encode(rawPassword);
  }

  /**
   * 判断明文和密文是否相同
   * 
   * @param rawPassword
   * @param password
   * @return
   */
  public static boolean match(String rawPassword, String password) {
    return ENCODER.matches(rawPassword, password);
  }

}
